import os
import glob
import random
import shutil
from pathlib import Path
import argparse


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--data_path', type=str, required=True)

    args = parser.parse_args()

    src_data = args.data_path


    root_dir = Path(src_data)
    for item1 in root_dir.iterdir():
        if item1.is_dir() is False:
            continue
        
        image_labels = []
        for item in item1.iterdir():
            if item.is_dir():
                label, name = item.name.split('_')
                
                images = glob.glob(f'{item}/*')
                images_num = len(images)
                
                for img_file in images:
                    image_label = f"{img_file},{label}"
                    image_labels.append(image_label)
            
                print(f'[INFO]{item}: num=={images_num}')
                
        with open(f'{item1}.txt', 'w') as f:
            for index, image_label in enumerate(image_labels):
                f.write(image_label)
                if index != len(image_labels) - 1:
                    f.write('\n')
        
        print(f'[INFO]{item1}: num=={len(image_labels)}')
